import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// 按需导入 element Plus
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

const { resolve } = require('path')

// https://vitejs.dev/config/
export default defineConfig({
  base: '',
  build: {
    outDir: 'dist',
    assetsDir: 'assets',
  },
  plugins: [
    vue(),
    // 按需导入 element Plus
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  // 起个别名，在引用资源时，可以用‘@/资源路径’直接访问
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src'),
      '@c': resolve(__dirname, 'src/components'),
      '@a': resolve(__dirname, 'src/assets'),
      '@u': resolve(__dirname, 'src/util'),
      '@v': resolve(__dirname, 'src/views'),
    },
  },
  // 配置前端服务地址和端口
  server: {
    port: 3001,
    // 是否开启 https
    https: false,
  },
})
